﻿using System;

namespace Algoritmia.Schemes.BranchAndBound
{
    public class BranchAndBoundState<TState, TDecision, TWeight> : IComparable<BranchAndBoundState<TState, TDecision, TWeight>>
        where TWeight : IComparable<TWeight>
    {
        public TWeight Priority { get; private set; }
        public BranchAndBoundDecision<TDecision> Decision { get; set; }
        public TState Current { get; private set; }
        public TState Previous { get; private set; }

        public BranchAndBoundState(TState s, TWeight priority, BranchAndBoundDecision<TDecision> decision, TState p)
        {
            Current = s;
            Priority = priority;
            Decision = decision;
            Previous = p;
        }

        #region Implementation of IComparable<in State>

        public int CompareTo(BranchAndBoundState<TState, TDecision, TWeight> other)
        {
            return Priority.CompareTo(other.Priority);
        }

        #endregion
    }

    public static class BranchAndBoundState
    {
        public static BranchAndBoundState<TState,TDecision,TWeight> Create<TState,TDecision,TWeight>(TState s, TWeight priority,
            BranchAndBoundDecision<TDecision> decision, TState p)
            where TWeight : IComparable<TWeight>
        {
            return new BranchAndBoundState<TState, TDecision, TWeight>(s,priority,decision,p);
        }
    }
}
